<template>
  <div class="case-query-page">
    <div class="title" slot="header">
      <span class="text">案件列表</span>
      <list-search :cols="columns" @search="searchParamChange"/>
    </div>
    <list-table ref="listTable" @selected="selected"/>
    <process-img ref="processImg"></process-img>
  </div>
</template>
<script>
  import ListTable from "@/views/comps/zhzf/list-table";
  import CustBtnCol from '@/views/comps/zhzf/list-table-col-btn';

  import utils from '@/assets/utils/zhzf-util';
  import dictCache from "@/assets/utils/cache-dict-util";
  import caseApi from "@/api/system/case";
  import ListSearch from "@/views/comps/zhzf/list-search";
  import HeadBtns from "@/views/comps/zhzf/head-btns";
  import processImg from "@/views/case/detail/process-img"
  import {mapState, mapMutations} from "vuex";
  import tabPageMinxin from "@/assets/minxin/tag-page";
  import detailView from "@/views/case/reg/detail-info";

  export default {
    mixins: [tabPageMinxin],
    components: {HeadBtns, ListSearch, ListTable, CustBtnCol,processImg},
    data() {
      return {
        currRow: {},
        columns: [
          {title: "案件编号", key: "caseNum", width: 180, sortable: "true"},
          {title: "立案地点", key: "fillingPlace", sortable: "true"},
          {
            title: "立案时间",
            key: "createTime",
            width: 150,
            sortable: "true",
            formatter: (row, col, val) => {
              return utils.formatDts(val, "YYYY-MM-DD HH:mm:ss");
            }
          },
          {title: "立案机构", key: "organName", width: 200, sortable: "true"},
          {title: "当事人", key: "party", width: 80, sortable: "true"},
          {
            title: "执行类型",
            key: "caseTypeId",
            width: 80,
            sortable: "true",
            formatter: (row, col, val) => {
              let dict = dictCache.getDataInfo("0048", val);
              return (dict && dict.name) || "一般程序";
            }
          },
          {
            title: "执法门类",
            key: "zfml",
            width: 80,
            sortable: "true",
            formatter: (row, col, val) => {
              let dict = dictCache.getDataInfo("0055", val);
              return (dict && dict.name) || "道路运政";
            }
          },
          {
            title: "执法人", key: "staffstr", width: 120, sortable: "true",
            formatter: (row, col, val) => {
              let dict = row;
              if (dict.statffs.length > 0) {
                return (dict.statffs[0].username)
              } else {
                return '--'
              }
            }
          },
          {title: "案件类型", key: "caseType", width: 80, sortable: "true"},
          {
            title: "当前环节", key: "linkName", width: 80, sortable: 'true'
          },
          // formatter: (row, col, val) => {
          //     let dict = dictCache.getDataInfo("0053", val);
          //     return (dict && dict.name) || "标准立案";
          //   }
          {
            title: "案件类型", key: "caseType", width: 80, sortable: 'true'
          },
          // , formatter: (row, col, val) => {
          //     let dict = dictCache.getDataInfo("0053", val);
          //     return (dict && dict.name) || "标准立案";
          //   }
          {
            title: "案件状态", key: "caseStatus", width: 80, sortable: 'true'
          },
          // , formatter: (row, col, val) => {
          //     let dict = dictCache.getDataInfo("0053", val);
          //     return (dict && dict.name) || "标准立案";
          //   }
          {
            title: '操作',
            key: 'op',
            component: {
              name: CustBtnCol,
              props: {
                items: [{text: '详情', emit: 'show-detail'}, {text: '流程', emit: 'show-workflow'}]
              }
            }
          }
        ],
      };
    },
    computed: {},
    mounted() {
      this.$bus.$off('show-workflow').$on('show-workflow', res => {
        this.currRow = res;
        let detail = {
          processInstanceId:this.currRow.processInstanceId,
          caseNo:this.currRow.caseNum
        }
        this.$refs.processImg.initPage(detail);
      });
      this.$bus.$off('show-detail').$on('show-detail', res => {
        let pageTitle = "案件详情";
        let rpath = "case/info/detail";
        let rname = "caseInfoDetail";
        this.addTabPage(pageTitle, rpath, rname, detailView, {row: res});
      });
      this.initPage();
    },
    methods: {
      ...mapMutations({
        pageInit: "d2admin/page/init"
      }),
      async searchParamChange(query) {
        await this.$refs.listTable.reloadData(query)
      },
      selected(rows) {
        // console.log(rows)
      },
      async initPage() {
        await this.$refs.listTable.initPage({
          method: caseApi.pageList,
          cols: this.columns
        })
      },
    }
  };
</script>
<style lang="scss">
  .case-reg-page {
    .d2-crud-body {
    }
  }
</style>
